﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YcBaseDomain.Abstract;

using PrjBaseWithAuth4.Domain.Entities;
using PrjBaseWithAuth4.Domain.Abstract;
using System.Linq.Expressions;

namespace PrjBaseWithAuth4.Domain.Concrete
{
    public class CommonRepository: ICommonRepository
    {
        public EFDbContext dbContext { get; set; }

        public CommonRepository(EFDbContext dbContext)
        {
            this.dbContext = dbContext;
        }

        public CommonRepository(IBaseDataBase baseDB)
        {
            this.dbContext = (baseDB.context as EFDbContext);
        }

        public EFDbContext getEFDbContext()
        {
            return this.dbContext;
        }

        public S_Portal getPortalById(int portalId)
        {
            return getEFDbContext().s_portals.FirstOrDefault(c => c.id == portalId);
        }

        public bool CheckExists<T>(Expression<Func<T, bool>> anyLambda) where T : class
        {
            return this.dbContext.Set<T>().Any(anyLambda);
        }

        public T FirstOrDefault<T>(Expression<Func<T, bool>> findLambda) where T : class
        {
            return this.dbContext.Set<T>().FirstOrDefault(findLambda);
        }
    }
}
